package wyj;

import java.util.Scanner;

class Main123 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int exp;
        int coef;

        exp = in.nextInt();
        int exp_A = exp;
        int [] A = new int[exp+1];
        coef = in.nextInt();
        A[exp] = coef;
        do{
            exp = in.nextInt();
            coef = in.nextInt();
            A[exp] = coef;
        }while(exp != 0);

        exp = in.nextInt();
        int exp_B = exp;
        int [] B = new int[exp+1];
        coef = in.nextInt();
        B[exp] = coef;
        do{
            exp = in.nextInt();
            coef = in.nextInt();
            B[exp] = coef;
        }while(exp != 0);

        if(exp_A == exp_B){
            for(int i = A.length-1; i >0; i--){
                A[i] += B[i];
                if(A[i] != 0){
                    if(i != 1){
                        System.out.print(A[i]+"x"+i+"+");
                    }
                    else{
                        System.out.print(A[i]+"x"+"+");
                    }
                }
            }
            System.out.print(A[0]+B[0]);
        }
    }
}

